package com.casic.common.utils.api;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.util.HashMap;
import java.util.Map;

/**
 * @Company 航天科技山西公司
 * @Project hitech-Common
 * @Package com.hitech.common
 * @ClassName ErrorInfo.java
 * @Description TODO(ErrorInfo)
 * @author yangying
 * @create 2016年9月21日-下午5:10:58
 */
public class ResultInfo {
	public static final int OK = 0;
	public static final int ISEMPTY = 1;
	public static final int QUERY_PAGE_ERROR= 2;
	public static final int PEOPLE_CARD_TICKET_CHECK_ERROR= 3;
	public static final int GET_APP_VERSION_ERROE = 4;
	public static final int OLD_PASSWORD_ERROR = 5;
	public static final int MODIFY_PASSWORD_ERROR = 6;
	public static final int NO_LOGIN = 7;
	public static final int LOGIN_OUT_ERROR = 8;
	public static final int LOGIN_FAILED= 10;
	public static final int USERNAME_PASSWORD_ERROR= 11;
	public static final int USERLOCKING= 12;
	public static final int USER_NONE= 13;
	public static final int UPLOAD_FILE_ERROR= 14;
	public static final int BINDING_USER_ERROR= 15;
	public static final int GET_USER_ERROR= 16;
	public static final int GET_CHECK_PAGE_ERROR= 17;
	public static final int GET_CHECK_INFO_ERROR= 18;
	public static final int SAVE_CHECK_DATA_ERROR= 19;
	public static final int PHOTO_ERROR= 20;
	public static final int TEXT_ERROR= 21;
	public static final int GET_CHECK_DATA_ERROR= 22;
	public static final int GET_CHECK_DATA_PAGE_ERROR= 23;
	public static final int TITLE_TEXT_ERROR= 24;
	public static final int GET_LEGAIPROVISIONS_ERROR= 25;
	public static final int GET_CYCLE_ENTERPRISE_ERROR= 26;
	public static final int GE_ENTERPRISE_CYCLE_DATA_ERROR= 27;




	public final static Map<Integer, String> ErrorMessageMap = new HashMap<Integer, String>();
	static {
		ErrorMessageMap.put(ResultInfo.OK,"请求成功！！");
		ErrorMessageMap.put(ResultInfo.ISEMPTY,"为空！！");
		ErrorMessageMap.put(ResultInfo.QUERY_PAGE_ERROR,"分页查询记录失败！！");
		ErrorMessageMap.put(ResultInfo.PEOPLE_CARD_TICKET_CHECK_ERROR,"保存核查信息失败！！");
		ErrorMessageMap.put(ResultInfo.GET_APP_VERSION_ERROE,"app获取版本信息失败！！");
		ErrorMessageMap.put(ResultInfo.OLD_PASSWORD_ERROR,"原密码错误！！");
		ErrorMessageMap.put(ResultInfo.MODIFY_PASSWORD_ERROR,"用户修改密码失败！！");
		ErrorMessageMap.put(ResultInfo.NO_LOGIN,"用户未登陆！！");
		ErrorMessageMap.put(ResultInfo.LOGIN_FAILED,"登陆失败！！");
		ErrorMessageMap.put(ResultInfo.LOGIN_OUT_ERROR,"用户退出失败！！");
		ErrorMessageMap.put(ResultInfo.USERNAME_PASSWORD_ERROR,"密码错误！！");
		ErrorMessageMap.put(ResultInfo.USERLOCKING,"用户锁定！！");
		ErrorMessageMap.put(ResultInfo.USER_NONE,"用户不存在！！");
		ErrorMessageMap.put(ResultInfo.UPLOAD_FILE_ERROR,"上传文件失败！！");
		ErrorMessageMap.put(ResultInfo.BINDING_USER_ERROR,"该用户在该机器上无法登陆，请联系管理员清除机器码！！");
		ErrorMessageMap.put(ResultInfo.GET_USER_ERROR,"获取用户信息失败！！");
		ErrorMessageMap.put(ResultInfo.GET_CHECK_PAGE_ERROR,"获取检查单列表错误！！");
		ErrorMessageMap.put(ResultInfo.GET_CHECK_INFO_ERROR,"获取检查单结构数据错误！！");
		ErrorMessageMap.put(ResultInfo.SAVE_CHECK_DATA_ERROR,"保存检查单数据出错！！");
		ErrorMessageMap.put(ResultInfo.PHOTO_ERROR,"选项必须拍照！！");
		ErrorMessageMap.put(ResultInfo.TEXT_ERROR,"选项必须录入文字！！");
		ErrorMessageMap.put(ResultInfo.GET_CHECK_DATA_ERROR,"获取检查单数据出错！！");
		ErrorMessageMap.put(ResultInfo.GET_CHECK_DATA_PAGE_ERROR,"获取检查填写数据列表错误！！");
		ErrorMessageMap.put(ResultInfo.TITLE_TEXT_ERROR,"标题必须录入文字！！");
		ErrorMessageMap.put(ResultInfo.GET_LEGAIPROVISIONS_ERROR,"获取法律条文出错！！");
		ErrorMessageMap.put(ResultInfo.GET_CYCLE_ENTERPRISE_ERROR,"查询需要填报检查单企业出错！！");
		ErrorMessageMap.put(ResultInfo.GE_ENTERPRISE_CYCLE_DATA_ERROR,"查询企业下需要填写的检查单出错！！");
	}
	/**
	 * @Title error
	 * @Description (错误)
	 * @author yangying
	 * @create 2016年9月21日-下午5:11:29
	 * @Param @param errorCode
	 * @Param @param name
	 * @Param @param msgcode
	 * @Param @return
	 * @return JSONObject
	 * @throws
	 */
	public static JSONObject error(int errorCode, String name) {
		ResultPojo resultPojo = new ResultPojo();
		resultPojo.setResultData(new JSONObject());
		resultPojo.setErrorCode(errorCode);
		resultPojo.setErrorMessage(name
				+ ResultInfo.ErrorMessageMap.get(errorCode));
		return (JSONObject) JSON.toJSON(resultPojo);
	}

	/**
	 * @Title error
	 * @Description (错误)
	 * @author yangying
	 * @create 2016年12月8日-下午2:53:28
	 * @Param @param errorCode
	 * @Param @param name
	 * @Param @param msgcode
	 * @Param @return
	 * @return JSONObject
	 * @throws 
	 */
	public static JSONObject errorMessage(int errorCode, String message) {
		ResultPojo resultPojo = new ResultPojo();
		resultPojo.setResultData(new JSONObject());
		resultPojo.setErrorCode(errorCode);
		resultPojo.setErrorMessage(message);
		return (JSONObject) JSON.toJSON(resultPojo);
	}

	/**
	 * 根据错误代码找错误信息
	 * @param errorCode
	 * @return
	 */
	public static JSONObject error(int errorCode) {
		ResultPojo resultPojo = new ResultPojo();
		resultPojo.setResultData(new JSONObject());
		resultPojo.setErrorCode(errorCode);
		resultPojo.setErrorMessage(ResultInfo.ErrorMessageMap.get(errorCode));
		return (JSONObject) JSON.toJSON(resultPojo);
	}
	
	/**
	 * @Title success
	 * @Description (成功)
	 * @author yangying
	 * @create 2016年9月21日-下午5:11:33
	 * @Param @param resultData
	 * @Param @return
	 * @Param @throws Exception
	 * @return JSONObject
	 * @throws
	 */
	public static JSONObject success(JSONObject resultData) throws Exception {
		ResultPojo resultPojo = new ResultPojo();
		resultPojo.setResultData(resultData);
		resultPojo.setErrorMessage("请求成功！！");
		resultPojo.setErrorCode(0);
		return (JSONObject) JSON.toJSON(resultPojo);
	}

	/**
	 * 传出jsonArray
	 * @param resultData
	 * @return
	 * @throws Exception
	 */
	public static JSONObject success(JSONArray resultData) throws Exception {
		ResultPojo resultPojo = new ResultPojo();
		resultPojo.setResultData(resultData);
		resultPojo.setErrorMessage("请求成功！！");
		resultPojo.setErrorCode(0);
		return (JSONObject) JSON.toJSON(resultPojo);
	}

	/**
	 * @Title success
	 * @Description (成功)
	 * @author yangying
	 * @create 2016年9月22日-下午1:29:38
	 * @Param @param resultData
	 * @Param @return
	 * @Param @throws Exception
	 * @return JSONObject
	 * @throws
	 */
	public static JSONObject success(String resultData) throws Exception {
		ResultPojo resultPojo = new ResultPojo();
		resultPojo.setResultData(JSON.parseObject(resultData));
		resultPojo.setErrorMessage("请求成功！！");
		resultPojo.setErrorCode(0);
		return (JSONObject) JSON.toJSON(resultPojo);
	}

	/**
	 * 请求成功，无数据返回
	 * @return
	 * @throws Exception
	 */
	public static JSONObject success() throws Exception {
		ResultPojo resultPojo = new ResultPojo();
		resultPojo.setResultData(new JSONObject());
		resultPojo.setErrorMessage("请求成功！！");
		resultPojo.setErrorCode(0);
		return (JSONObject) JSON.toJSON(resultPojo);
	}
}
